home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ead / ead28.dms / ead28.adf / Listati / sm.c < prev    next >
C/C++ Source or Header  |  1991-03-10  |  4KB  |  184 lines

  1.  
  2. /* ***********************************************************************
  3.  
  4. Programma ........ ScreenShift
  5.  
  6. Autore ........... Anson Mah, adattamento a 5.04 di Olli
  7.  
  8. Versione ......... 1.0, 4 giugno 1987
  9.  
  10. Funzione ......... Centratura dello schermo via gadget
  11.  
  12. Compilazione ..... LC -vbr -cusfi -O -Lntv ScreenShift.c
  13.  
  14. Note ............. Traduzione e revisione per V5.10 di Luigi Callegari
  15.  
  16. ************************************************************************ */
  17.  
  18. #include <intuition/intuition.h>
  19.  
  20. #ifdef LATTICE
  21. #  include <proto/intuition.h>
  22. #  include <proto/exec.h>
  23. #else
  24. # include <functions.h>
  25. #endif
  26.  
  27. #define PROPGADWIDTH    200    /* Gadget propozionale */
  28. #define PROPGADHEIGHT    50
  29. #define XJUMP           512    
  30. #define YJUMP           1024    
  31. #define UP              0x4c    
  32. #define DOWN            0x4d    
  33. #define LEFT            0x4f  
  34. #define RIGHT           0x4e
  35. #define CR              0x44  /* Tasto RETURN */
  36.  
  37. extern UWORD xoffset(BYTE), yoffset(BYTE);  /* Le routines di Math.asm */
  38. extern BYTE xpot(UWORD), ypot(UWORD);
  39.  
  40. UWORD piData[60] = {
  41.    0x0000,0x0000,0x0000,
  42.    0x7FFF,0xFFFF,0xFE00,
  43.    0x7FFF,0xB7DF,0xFE00,
  44.    0x7FFB,0xDBDF,0xFE00,
  45.    0x7FFD,0xFDDF,0xFE00,
  46.    0x7FFF,0xDADF,0xFE00,
  47.    0x7FFB,0xDBDF,0xFE00,
  48.    0x7FFF,0xBBDF,0xFE00,
  49.    0x7FFF,0xFFFF,0xFE00,
  50.    0x0000,0x0000,0x0000,
  51.    0xFFFF,0xFFFF,0xFF00,
  52.    0xFFFF,0xFFFF,0xFF00,
  53.    0xFFF0,0x6FBF,0xFF00,
  54.    0xFFE7,0x273F,0xFF00,
  55.    0xFFE3,0xE23F,0xFF00,
  56.    0xFFFE,0x253F,0xFF00,
  57.    0xFFE7,0x273F,0xFF00,
  58.    0xFFF0,0x673F,0xFF00,
  59.    0xFFFF,0xFFFF,0xFF00,
  60.    0xFFFF,0xFFFF,0xFF00
  61. };
  62.  
  63. struct Image piImage = {
  64.     0, 0,       /* LeftEdge, TopEdge */
  65.     40, 10, 2,  /* Width, Height, Depth */
  66.     &piData[0], /* ImageData */
  67.     0x03, 0x00, /* PlanePick, PlaneOnOff */
  68.     NULL        /* NextImage */
  69. };
  70.  
  71.  
  72.  
  73. struct PropInfo pinfo = {
  74.    FREEVERT | FREEHORIZ,
  75.    0,0, MAXBODY/5,MAXBODY/5,
  76.    0,0,0,0,0
  77. };
  78.  
  79. struct Gadget pgadget = {
  80.    NULL, 0, 10, PROPGADWIDTH, PROPGADHEIGHT, GADGIMAGE, FOLLOWMOUSE,
  81.    PROPGADGET, (APTR)&piImage, NULL, NULL, 0, (APTR)&pinfo,
  82.    0, NULL
  83. };
  84.  
  85. struct NewWindow pwindef = {
  86.    220, 70,
  87.    PROPGADWIDTH, PROPGADHEIGHT + 10,
  88.    0, 3,
  89.    CLOSEWINDOW | MOUSEMOVE | RAWKEY,
  90.    WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | ACTIVATE | SMART_REFRESH | RMBTRAP,
  91.    &pgadget,
  92.    NULL,
  93.    "ScreenMove",
  94.    NULL, NULL,
  95.    0,0, 0,0,
  96.    WBENCHSCREEN
  97. };
  98.  
  99. void _main( void );
  100.  
  101. void XCEXIT( int );
  102.  
  103. void _main( void )
  104. {
  105.     struct IntuiMessage *msg;
  106.     ULONG class, code;
  107.     BYTE c_xoffset, c_yoffset;
  108.     struct IntuitionBase *IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 33);
  109.     struct Preferences pref;
  110.     struct Window *pwin;
  111.  
  112.    /* Legge preferenze attuali */
  113.  
  114.     (void)GetPrefs(&pref, sizeof(struct Preferences));
  115.  
  116.    /* Fissa gadget proporzionale per setting di View attuali */
  117.  
  118.     pinfo.HorizPot = xoffset(pref.ViewXOffset);
  119.     pinfo.VertPot = yoffset(pref.ViewYOffset);
  120.     if (!(pwin = (struct Window *)OpenWindow(&pwindef)))
  121.         goto exit;
  122.  
  123.     for (;;) {
  124.         WaitPort( pwin -> UserPort );
  125.         msg = (struct IntuiMessage *) GetMsg(pwin -> UserPort);
  126.         class = msg -> Class;
  127.         code = msg -> Code;
  128.         ReplyMsg( (struct Message *) msg );
  129.  
  130.         switch ( class ) {
  131.             case CLOSEWINDOW:
  132.                 goto exit;
  133.  
  134.             case RAWKEY:
  135.               switch (code) {
  136.                 case UP:
  137.                     if (pinfo.VertPot >= YJUMP)
  138.                         pinfo.VertPot -= YJUMP;
  139.                     else    pinfo.VertPot = 0;
  140.                     break;
  141.  
  142.                 case DOWN:
  143.                     if (pinfo.VertPot < MAXBODY - YJUMP)
  144.                         pinfo.VertPot += YJUMP;
  145.                     else    pinfo.VertPot = MAXBODY;
  146.                     break;
  147.  
  148.                 case LEFT:
  149.                     if (pinfo.HorizPot >= XJUMP)
  150.                         pinfo.HorizPot -= XJUMP;
  151.                     else    pinfo.HorizPot = 0;
  152.                     break;
  153.  
  154.                 case RIGHT:
  155.                     if (pinfo.HorizPot < MAXBODY - XJUMP)
  156.                         pinfo.HorizPot += XJUMP;
  157.                     else    pinfo.HorizPot = MAXBODY;
  158.                     break;
  159.  
  160.                 case CR:    /* carriage return */
  161.                     goto exit;
  162.               }
  163.  
  164.               RefreshGadgets(&pgadget, pwin, NULL);
  165.  
  166.             case MOUSEMOVE:
  167.                 c_xoffset = xpot(pinfo.HorizPot);
  168.                 c_yoffset = ypot(pinfo.VertPot);
  169.                 if (pref.ViewXOffset != c_xoffset || pref.ViewYOffset != c_yoffset) {
  170.                     pref.ViewXOffset = c_xoffset;
  171.                     pref.ViewYOffset = c_yoffset;
  172.                     (void)SetPrefs(&pref, sizeof(struct Preferences), FALSE);
  173.                 }
  174.                 break;
  175.         }
  176.     }
  177.  
  178. exit:
  179.     if( pwin )
  180.       CloseWindow(pwin);
  181.     XCEXIT(0);
  182. }
  183.  
  184.